package com.zwy.Shopping.servlet_;

import javax.servlet.*;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;

@WebServlet("/upload")
@MultipartConfig
    public class FileUpload_Servlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取文件
        Part part =req.getPart("file1");
        String fileName = part.getSubmittedFileName();//获得头像的名字
        System.out.println(fileName);
        //构建文件上传路径
        String path = "D:\\学习\\服装购买系统\\ShoppingClothes\\web\\img\\";
        path += fileName;

        part.write(path);
    }
}

